package com.ophiux.cs.application.appraise.remote;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.ophiux.cs.application.consultOrder.dto.GetConsultOrderByRecordIdRequest;
import com.ophiux.cs.application.consultOrder.dto.GetConsultOrderByRecordIdResponse;
import com.ophiux.cs.application.consultOrder.dto.UpdateCSOrderRecordsRequest;
import com.ophiux.cs.application.consultOrder.dto.UpdateCSOrderRecordsResponse;
import com.ophiux.cs.application.consultOrder.service.IGetConsultOrderByRecordIdAppService;
import com.ophiux.cs.application.consultOrder.service.IUpdateCSOrderRecordsAppService;
import com.ophiux.cs.application.core.Result;
import com.ophiux.cs.domain.appraise.model.valueobj.Appraise_ConsultOrder;
import com.ophiux.cs.domain.appraise.remote.IAppraise_ConsultOrderRemoteService;
import com.ophiux.utils.common.ShiftUtils;
import com.ophiux.utils.exception.OphiuxRemoteException;
import com.ophiux.utils.parser.json.JsonUtils;

import lombok.extern.slf4j.Slf4j;

@Service
@Slf4j
public class Appraise_ConsultOrderRemoteService implements IAppraise_ConsultOrderRemoteService {
	@Autowired
	IGetConsultOrderByRecordIdAppService getConsultOrderByRecordIdAppService;
	@Autowired

	IUpdateCSOrderRecordsAppService updateCSOrderRecordsAppService;
	@Override
	public Appraise_ConsultOrder getConsultOrderByRecordId(String recordId) throws OphiuxRemoteException{
		try {
			GetConsultOrderByRecordIdRequest dto = new GetConsultOrderByRecordIdRequest();
			dto.setRECORD_ID(recordId);
			
			Result<GetConsultOrderByRecordIdResponse> result = getConsultOrderByRecordIdAppService.GetConsultOrderByRecordId(dto);
			if(!result.isSuccess()) {
				log.info("调用远程API,Appraise_ConsultOrderRemoteService=>getConsultOrderByRecordId失败,返回参数",JsonUtils.toJson(result));
				throw new OphiuxRemoteException("调用远程API,Appraise_ConsultOrderRemoteService=>getConsultOrderByRecordId失败");
			}

			Appraise_ConsultOrder resp = (Appraise_ConsultOrder) ShiftUtils.objToNewObj(result.getRESPONSE(), Appraise_ConsultOrder.class);
			return resp;
		} catch (Exception e) {
			e.printStackTrace();
			log.info("调用远程API,Appraise_ConsultOrderRemoteService=>getConsultOrderIsExist异常",e);
			throw new OphiuxRemoteException(e);
		}
	}

	@Override
	public void updateConsultOrderAppraiseStatus(String recordId) throws OphiuxRemoteException {
		try {
			UpdateCSOrderRecordsRequest dto = new UpdateCSOrderRecordsRequest();
			dto.setRECORD_ID(recordId);
			
			Result<UpdateCSOrderRecordsResponse> result = updateCSOrderRecordsAppService.updateCSOrderRecord(dto);
			if(!result.isSuccess()) {
				log.info("调用远程API,Appraise_ConsultOrderRemoteService=>updateConsultOrderAppraiseStatus失败,返回参数",JsonUtils.toJson(result));
				throw new OphiuxRemoteException("调用远程API,Appraise_ConsultOrderRemoteService=>updateConsultOrderAppraiseStatus失败");
			}
			
		} catch (Exception e) {
			e.printStackTrace();
			log.info("调用远程API,Appraise_ConsultOrderRemoteService=>updateConsultOrderAppraiseStatus异常",e);
			throw new OphiuxRemoteException(e);
		}
	}

}
